package com.bjsxt.service.impl;

import com.bjsxt.service.BusinessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BusinessServiceImpl implements BusinessService {

    private static Logger logger = LoggerFactory.getLogger(BusinessServiceImpl.class) ;

    @Autowired
    private StorageServiceApi storageServiceApi ;

    @Autowired
    private OrderServiceApi orderServiceApi ;

    @Override
    public void purchase(String userId, String productNo, int count) {
        logger.info("准备下单，用户{}，商品{}，数量{}",userId ,productNo ,count);
        // 1 远程调用库存服务--> 库存的扣减f
        storageServiceApi.deduct(productNo, count);
        // 2 远程调用订单服务-->订单的新增
        orderServiceApi.create(userId, productNo, count);

        logger.info("下单成功");
    }
}
